// 获取文章标题函数
function GetRequest() {
    var str = location.href
    var num = str.indexOf("#");
    if(num == -1) {
        return '';
    }
    str = str.substr(num + 1);
    return str;
}

//文章的URL标题
var uTitle = GetRequest();
if(uTitle == '') {
    alert('文章不存在！');
}

//QQ空间分享URL
var Qurl = "https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?&url="+encodeURI(window.location.href)+"&title=%E5%88%86%E4%BA%AB%E6%96%87%E7%AB%A0%EF%BC%9A&summary=%E7%8E%8B%E5%AD%90%E9%89%B4%E7%9A%84%E5%B0%8F%E4%B8%96%E7%95%8C&pics=";
//截断URL文章标题切换
window.onhashchange = function(){var uTitle = GetRequest();
    if(uTitle == '') {
        alert('文章不存在！');
    }init();};

//获取文章信息
function getArticleInfo() {
    $.get('data/article/'+uTitle+'/info.json',{},function(data) {
        document.title = data.title;
        document.getElementById('article-head-title').innerHTML = data.title;
        document.getElementById('author-name').innerHTML = data.author;
        document.getElementById('time-value').innerHTML = data.time;
    });
}

//获取文章内容
function getArticleContent() {
    $.get('data/article/'+uTitle+'/content.html',{},function(data) {
        document.getElementById('article-content-main').innerHTML = data;
    });
}

function init() {
    getArticleInfo();
    getArticleContent();
}

//分享到QQ空间
function shareToQQ() {
    window.open(Qurl);
}

init();